#pragma once
#include "UDialog.h"

class UIAPI UKeyboard : public UDialog
{
	UDEC_CLASS(UKeyboard);
public:
	enum Keys
	{
		K_UNKNOWN = 0,
		K_1,
		K_2,
		K_3,
		K_4,
		K_5,
		K_6,
		K_7,
		K_8,
		K_9,
		K_0,
		K_A,
		K_B,
		K_C,
		K_D,
		K_E,
		K_F,
		K_G,
		K_H,
		K_I,
		K_J,
		K_K,
		K_L,
		K_M,
		K_N,
		K_O,
		K_P,
		K_Q,
		K_R,
		K_S,
		K_T,
		K_U,
		K_V,
		K_W,
		K_X,
		K_Y,
		K_Z,
		K_CAPSLOCK,
		K_BACKSPACE,
		K_CLOSE,
		K_MAX,
	};
	enum ButtonState
	{
		BS_NORMAL = 0,
		BS_OVER =1,
		BS_DOWN =2,
		BS_CHECK = 4,
	};
	struct Button
	{
		inline Button():Key(K_UNKNOWN),State(BS_NORMAL),Flags(0),Ascii(0)
		{
		}
		WORD Key;
		BYTE State;
		BYTE Flags;
		WORD Ascii;
		VRect Rect;
		VRect UVRect;
	};
	UKeyboard(void);
	~UKeyboard(void);
	
	void LayoutButtons(BOOL Random = FALSE, UINT Seed = 0);
	void OpenKeyBoard();
	void Init(UKeyboard* m_Keyboard);
	virtual void Close() {}
protected:
	virtual void GetKeyRect(UINT Key, VRect& Rect);
	virtual void GetKeyUVRect(UINT Key, VRect& Rect);
	virtual BOOL OnCreate();
	virtual void OnDestroy();
	virtual void OnRender(const VPoint& offset, const VRect &updateRect);

	virtual void OnMouseUp(const VPoint& position, UINT flags);
	virtual void OnMouseDown(const VPoint& point, UINT nRepCnt, UINT uFlags);
	virtual void OnMouseMove(const VPoint& position, UINT flags);
	virtual void OnMouseEnter(const VPoint& position, UINT flags);
	virtual void OnMouseLeave(const VPoint& position, UINT flags);
	virtual void DrawButtons(const VPoint& offset);
	UINT FindButton(const VPoint& point) const;
	void KeyUp(UINT Key);
	UString		m_strBtnSkin;
	UTexturePtr m_spButtonSkin;
	BOOL		m_CapsLocked;
	UINT		m_MouseOver;
	UINT		m_PressedButton;
	Button m_Buttons[K_MAX];
	BOOL m_RandomKeyPos;
};
